package com.haredot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.haredot.entity.Logger;
import com.haredot.mapper.LoggerMapper;
import com.haredot.service.LogService;
import com.haredot.vo.PageVo;
import com.haredot.vo.R;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class LogServiceImpl implements LogService {

    @Resource
    private LoggerMapper loggerMapper ;

    @Override
    public R<PageVo> queryLoggers(PageVo pageVo, Map<String, Object> params) {

        PageInfo<Logger> objectPageInfo = PageHelper.startPage(pageVo)
                .doSelectPageInfo(() -> loggerMapper.findAll(params));

        pageVo.setTotal(objectPageInfo.getTotal()).setList(objectPageInfo.getList());

        return R.<PageVo>ok().data(pageVo);
    }

    @Override
    public R<PageVo> querySignLogger(PageVo pageVo, Map<String, Object> params) {

        PageInfo<Logger> objectPageInfo = PageHelper.startPage(pageVo)
                .doSelectPageInfo(() -> loggerMapper.findSignLogAll(params));

        pageVo.setTotal(objectPageInfo.getTotal()).setList(objectPageInfo.getList());

        return R.<PageVo>ok().data(pageVo);
    }
}
